<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="用户id" prop="userId">
      <el-input v-model="dataForm.userId" placeholder="用户id"></el-input>
    </el-form-item>
    <el-form-item label="标题" prop="title">
      <el-input v-model="dataForm.title" placeholder="标题"></el-input>
    </el-form-item>
    <el-form-item label="0待付款 1待接单 2待完成 3已完成 4已取消" prop="state">
      <el-input v-model="dataForm.state" placeholder="0待付款 1待接单 2待完成 3已完成 4已取消"></el-input>
    </el-form-item>
    <el-form-item label="描述" prop="des">
      <el-input v-model="dataForm.des" placeholder="描述"></el-input>
    </el-form-item>
    <el-form-item label="1 删除;2 没有删除" prop="isDelete">
      <el-input v-model="dataForm.isDelete" placeholder="1 删除;2 没有删除"></el-input>
    </el-form-item>
    <el-form-item label="创建时间" prop="creareTime">
      <el-input v-model="dataForm.creareTime" placeholder="创建时间"></el-input>
    </el-form-item>
    <el-form-item label="地区id" prop="aId">
      <el-input v-model="dataForm.aId" placeholder="地区id"></el-input>
    </el-form-item>
    <el-form-item label="总金额" prop="totalFee">
      <el-input v-model="dataForm.totalFee" placeholder="总金额"></el-input>
    </el-form-item>
    <el-form-item label="?" prop="formId">
      <el-input v-model="dataForm.formId" placeholder="?"></el-input>
    </el-form-item>
    <el-form-item label="目的地" prop="mu">
      <el-input v-model="dataForm.mu" placeholder="目的地"></el-input>
    </el-form-item>
    <el-form-item label="起点" prop="qi">
      <el-input v-model="dataForm.qi" placeholder="起点"></el-input>
    </el-form-item>
    <el-form-item label="订单数量" prop="orderNum">
      <el-input v-model="dataForm.orderNum" placeholder="订单数量"></el-input>
    </el-form-item>
    <el-form-item label="1 付款;0未付款" prop="isPay">
      <el-input v-model="dataForm.isPay" placeholder="1 付款;0未付款"></el-input>
    </el-form-item>
    <el-form-item label="接单人ID" prop="jdId">
      <el-input v-model="dataForm.jdId" placeholder="接单人ID"></el-input>
    </el-form-item>
    <el-form-item label="?" prop="openid">
      <el-input v-model="dataForm.openid" placeholder="?"></el-input>
    </el-form-item>
    <el-form-item label="?" prop="page">
      <el-input v-model="dataForm.page" placeholder="?"></el-input>
    </el-form-item>
    <el-form-item label="付款时间" prop="payTime">
      <el-input v-model="dataForm.payTime" placeholder="付款时间"></el-input>
    </el-form-item>
    <el-form-item label="接单时间" prop="jdTime">
      <el-input v-model="dataForm.jdTime" placeholder="接单时间"></el-input>
    </el-form-item>
    <el-form-item label="完成时间" prop="comTime">
      <el-input v-model="dataForm.comTime" placeholder="完成时间"></el-input>
    </el-form-item>
    <el-form-item label="取消时间" prop="cancelTime">
      <el-input v-model="dataForm.cancelTime" placeholder="取消时间"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          id: 0,
          userId: '',
          title: '',
          state: '',
          des: '',
          isDelete: '',
          creareTime: '',
          aId: '',
          totalFee: '',
          formId: '',
          mu: '',
          qi: '',
          orderNum: '',
          isPay: '',
          jdId: '',
          openid: '',
          page: '',
          payTime: '',
          jdTime: '',
          comTime: '',
          cancelTime: ''
        },
        dataRule: {
          userId: [
            { required: true, message: '用户id不能为空', trigger: 'blur' }
          ],
          title: [
            { required: true, message: '标题不能为空', trigger: 'blur' }
          ],
          state: [
            { required: true, message: '0待付款 1待接单 2待完成 3已完成 4已取消不能为空', trigger: 'blur' }
          ],
          des: [
            { required: true, message: '描述不能为空', trigger: 'blur' }
          ],
          isDelete: [
            { required: true, message: '1 删除;2 没有删除不能为空', trigger: 'blur' }
          ],
          creareTime: [
            { required: true, message: '创建时间不能为空', trigger: 'blur' }
          ],
          aId: [
            { required: true, message: '地区id不能为空', trigger: 'blur' }
          ],
          totalFee: [
            { required: true, message: '总金额不能为空', trigger: 'blur' }
          ],
          formId: [
            { required: true, message: '?不能为空', trigger: 'blur' }
          ],
          mu: [
            { required: true, message: '目的地不能为空', trigger: 'blur' }
          ],
          qi: [
            { required: true, message: '起点不能为空', trigger: 'blur' }
          ],
          orderNum: [
            { required: true, message: '订单数量不能为空', trigger: 'blur' }
          ],
          isPay: [
            { required: true, message: '1 付款;0未付款不能为空', trigger: 'blur' }
          ],
          jdId: [
            { required: true, message: '接单人ID不能为空', trigger: 'blur' }
          ],
          openid: [
            { required: true, message: '?不能为空', trigger: 'blur' }
          ],
          page: [
            { required: true, message: '?不能为空', trigger: 'blur' }
          ],
          payTime: [
            { required: true, message: '付款时间不能为空', trigger: 'blur' }
          ],
          jdTime: [
            { required: true, message: '接单时间不能为空', trigger: 'blur' }
          ],
          comTime: [
            { required: true, message: '完成时间不能为空', trigger: 'blur' }
          ],
          cancelTime: [
            { required: true, message: '取消时间不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            this.$http({
              url: this.$http.adornUrl(`/bbl/heiplist/info/${this.dataForm.id}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.userId = data.heiplist.userId
                this.dataForm.title = data.heiplist.title
                this.dataForm.state = data.heiplist.state
                this.dataForm.des = data.heiplist.des
                this.dataForm.isDelete = data.heiplist.isDelete
                this.dataForm.creareTime = data.heiplist.creareTime
                this.dataForm.aId = data.heiplist.aId
                this.dataForm.totalFee = data.heiplist.totalFee
                this.dataForm.formId = data.heiplist.formId
                this.dataForm.mu = data.heiplist.mu
                this.dataForm.qi = data.heiplist.qi
                this.dataForm.orderNum = data.heiplist.orderNum
                this.dataForm.isPay = data.heiplist.isPay
                this.dataForm.jdId = data.heiplist.jdId
                this.dataForm.openid = data.heiplist.openid
                this.dataForm.page = data.heiplist.page
                this.dataForm.payTime = data.heiplist.payTime
                this.dataForm.jdTime = data.heiplist.jdTime
                this.dataForm.comTime = data.heiplist.comTime
                this.dataForm.cancelTime = data.heiplist.cancelTime
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/bbl/heiplist/${!this.dataForm.id ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'id': this.dataForm.id || undefined,
                'userId': this.dataForm.userId,
                'title': this.dataForm.title,
                'state': this.dataForm.state,
                'des': this.dataForm.des,
                'isDelete': this.dataForm.isDelete,
                'creareTime': this.dataForm.creareTime,
                'aId': this.dataForm.aId,
                'totalFee': this.dataForm.totalFee,
                'formId': this.dataForm.formId,
                'mu': this.dataForm.mu,
                'qi': this.dataForm.qi,
                'orderNum': this.dataForm.orderNum,
                'isPay': this.dataForm.isPay,
                'jdId': this.dataForm.jdId,
                'openid': this.dataForm.openid,
                'page': this.dataForm.page,
                'payTime': this.dataForm.payTime,
                'jdTime': this.dataForm.jdTime,
                'comTime': this.dataForm.comTime,
                'cancelTime': this.dataForm.cancelTime
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
